/*global document */
(function() {
    function _class(className){
        if(document.getElementsByClassName){
            return document.getElementsByClassName(className);
        }
        else{
            var collection = [];
            var elements = document.getElementsByTagName('*');
            for(var i = 0, l = elements.length; i < l; i++){
                if(elements[i].className === 'className')
                    collection.push(elements[i]);
            }

            return collection;
        }
    }

    var source = _class('prettyprint source linenums');
    var i = 0;
    var lineNumber = 0;
    var lineId;
    var lines;
    var totalLines;
    var anchorHash;

    if (source && source[0]) {
        anchorHash = document.location.hash.substring(1);
        lines = source[0].getElementsByTagName('li');
        totalLines = lines.length;

        for (; i < totalLines; i++) {
            lineNumber++;
            lineId = 'line' + lineNumber;
            lines[i].id = lineId;
            if (lineId === anchorHash) {
                lines[i].className += ' selected';
            }
        }
    }
})();
